<template>
  <div>
    <h3>当前最新的count值为：{{$store.state.count}}</h3>
    <h3>{{$store.getters.showNum}}</h3>
    <button @click="btnHandle1">+1</button>
    <button @click="btnHandle2">+N</button>
    <button @click="btnHandle3">+1 ASYNC</button>
    <button @click="btnHandle4">+N ASYNC</button>
  </div>
</template>

<script>
export default {
  name: 'Addition',
  data () {
    return {}
  },
  methods: {
    btnHandle1 () {
      // this.$store.state.count++
      this.$store.commit('add')
    },
    btnHandle2 () {
      // commit的作用就是调用mutation函数
      this.$store.commit('addN', 3)
    },
    // 异步count自增1
    btnHandle3 () {
      // dispatch 专门用来触发 action
      this.$store.dispatch('addAsync')
    },
    btnHandle4 () {
      this.$store.dispatch('addNAsync', 3)
    }
  }
}
</script>

<style scoped>

</style>
